/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Data;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import javax.swing.JOptionPane;

/**
 *
 * @author Anh Trinh Tuan
 */
public class Conn {

//    public static void saveFile(SetGetSvInfo svinfo){
//        try{
//            FileWriter fw = new FileWriter(new File("ServerInfo.dat"));
//            BufferedWriter bw = new BufferedWriter(fw);
//            bw.write(svinfo.getServer());
//            bw.write(svinfo.getPort());
//            bw.write(svinfo.getDatabase());
//            bw.write(svinfo.getUser());
//            bw.write(svinfo.getPass());
//            bw.flush();
//            bw.close();
//            fw.close();
//        }
//        catch(Exception ex){
//            ex.printStackTrace();
//        }
//    }

    public static void Connection(SetGetSvInfo svinfo){
        try{
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        }
        catch(Exception ex){
            ex.printStackTrace();
        }

        try{
            String connectionUrl = "jdbc:sqlserver://" + svinfo.getServer() + ":"
                    + svinfo.getPort() + ";" + "databasename =" + svinfo.getDatabase()
                    + ";" + "user =" + svinfo.getUser() + ";" + "Password =" + svinfo.getPass();

            Connection conn =  DriverManager.getConnection(connectionUrl);
            JOptionPane.showMessageDialog(null,"Load Driver Success!","Message",JOptionPane.INFORMATION_MESSAGE);
        }
        catch(Exception ex){
            JOptionPane.showMessageDialog(null,"Load Driver UnSuccess!","Error",JOptionPane.ERROR_MESSAGE);
        }
    }
}

